package com.cedifie.lendapp.ui.user.impl

import com.cedifie.lendapp.http.ApiService
import com.cedifie.lendapp.http.ApiService.addCommonParams
import com.cedifie.lendapp.http.HttpHelper
import com.cedifie.lendapp.http.IHttpCallback
import com.cedifie.analysis.util.GoogleInstallUtil
import org.json.JSONObject

/**
 * Cedifie
 * @Author wwdeng
 * @CreateTime: 2024/6/14 16:26
 * @Annotation：用户登录 Model 实现
 */
class CedUserLoginModelImpl {

    /**
     * 发送验证码
     */
    fun sendCedSmsCodeAction(mobile: String, callBack: IHttpCallback) {
        val httpUrl = ApiService.getHttpUrl(ApiService.API_URL.CED_API_SMS_URL)
        val params = JSONObject().addCommonParams().apply {
            put("path",ApiService.API_PATH.CED_API_SEND_SMS_PATH)
            put("mobile",mobile)
        }
        HttpHelper.postCedAction(httpUrl,params,callBack)
    }

    /**
     * 登录
     */
    fun loginCedAction(mobile: String,code: String,directLoginFlag: String,callBack: IHttpCallback){
        val httpUrl = ApiService.getHttpUrl(ApiService.API_URL.CED_API_LOGIN_URL)
        val params = JSONObject().addCommonParams().apply {
            put("path",ApiService.API_PATH.CED_API_LOGIN_PATH)
            put("mobile",mobile)//手机号
            put("code",code)//验证码
            put("channelCode", GoogleInstallUtil.getInstallReferrer())//渠道号
            put("subChannelCode", GoogleInstallUtil.getInstallReferrer())//子渠道号
            put("directLoginFlag",directLoginFlag)//是否直接登录
        }
        HttpHelper.postCedAction(httpUrl,params,callBack)
    }

    /**
     * 2025-04-09 更新为后置校验流程，直接调无验证码登录接口即可
     */
    fun loginCedNoCodeAction(mobile: String,callBack: IHttpCallback){
        val httpUrl = ApiService.getHttpUrl(ApiService.API_URL.CED_API_LOGIN_URL)
        val params = JSONObject()
            .addCommonParams()
            .apply {
                put("path",ApiService.API_PATH.CED_API_LOGIN_NO_CODE_PATH)
                put("mobile",mobile)//手机号
                put("code","0000")//验证码
                put("channelCode", GoogleInstallUtil.getInstallReferrer())//渠道号
                put("subChannelCode", GoogleInstallUtil.getInstallReferrer())//子渠道号
                put("directLoginFlag","YES")//是否直接登录
                put("notBindWalletFlag","YES")//不自动绑卡
                put("loginParam","")//验证码接口返回的参数
            }
        HttpHelper.postCedAction(httpUrl,params,callBack)
    }
}